package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.po.RoleMenuPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface RoleMenuMapper extends JpaRepository<RoleMenuPO, Long>, JpaSpecificationExecutor<RoleMenuPO> {
    @Query(value = "select p from RoleMenuPO p where p.roleId = :roleId and p.menuId = :menuId")
    RoleMenuPO findByRoleAndMenu(long roleId, long menuId);

    @Query(value = "select p.menuId from RoleMenuPO p where p.roleId = :roleId")
    Collection<Long> findMenuIdsByRole(long roleId);

    @Query(value = "select distinct p.menuId from RoleMenuPO p where p.roleId in (:roleIds)")
    Collection<Long> findMenuIdsByRoles(Collection<Long> roleIds);
}
